<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" content="ie=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品列表管理</title>
<#include "../common/easyui-html5.ftl"/>
    <#--<script src="//cdn.ckeditor.com/4.5.8/standard/ckeditor.js"></script>-->
    <script src="${rc.contextPath}/ckeditor/ckeditor.js" type="application/javascript"></script>

</head>
<body class="easyui-layout">
	 <div data-options="region:'center'">
		<table id="dg"></table>
	</div>
	<!-- 工具条  -->
	<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<table width="100%">
			<tr width="100%">
				<td width="50%">
					名称: <input class="easyui-textbox" style="line-height:12px; width:200px" id="brand_Name"/>
					<!--
					状态:<select class="easyui-combobox" data-options="editable:false,panelHeight:'auto'" style="width:100px" id="role_status">
						<option value="0">不限</option>
						<option value="1">有效</option>
						<option value="2">待审核</option>
						<option value="3">锁定</option>
					</select> -->
					<a href="#"  class="easyui-linkbutton" iconCls="icon-search" onclick="searchFn()">查询</a>
				</td>
				<td align="right" width="50%">
					<a id="addBtn" href="#" class="easyui-linkbutton" iconCls="add_btn" plain="true" onclick="addFn()">增加</a>
				</td>
			</tr>
		</table>
		</div>
	</div>
	<!-- 弹出窗口  -->
	<div id="w" class="easyui-window"
		data-options="modal:true,closed:true,iconCls:'icon-save',
		collapsible:false,minimizable:false,maximizable:false,resizable:false"
			style="width:600px;height:300px;padding:10px;">
			<div class="easyui-layout" data-options="fit:true">
					<div data-options="region:'center',border:false" style="padding:0px;">
                        <form id="form1"  method="post"   enctype="multipart/form-data"  style="height: 100%;" >
                            <input name="isAjax" value="1" type="hidden">
							<div id="tt" class="easyui-tabs"  data-options="fit:true,plain:true,narrow:true,pill:true,justified:true" >
								<div title="通用信息" style="padding:5px">
                                    <table cellpadding="5">
                                        <tr>
                                            <td>商品名称:</td>
                                            <td><input class="easyui-textbox" type="text" name="goodsName" id="goodsName" data-options="required:true"  style="width:250px;"></input></td>

                                            <td>商品货号:</td>
                                            <td><input class="easyui-textbox" type="text" name="goodsSn" id="goodsSn" data-options="required:true"  style="width:250px;"></input></td>
                                        </tr>
                                        <tr>
                                            <td>商品分类:</td>
                                            <td>
                                                <select  name="catId" id="catId" class="easyui-combotree" style="width:250px;"
                                                         data-options="url:'${rc.contextPath}/admin/common/category/list',
                                                        required:true,
                                                        method:'get',
                                                         panelHeight:'auto',
                                                         valueField:'id',
                                                        loadFilter:function(data){
                                                       	if(data.statusCode == normalStatusCode){
																				return treeloadFilter(data.entity,false);
																	}else {
																		return  [];
																	}
                                                				}
                                                       ">
                                                </select>
                                            </td>
                                            <td>扩展分类:</td>
                                            <td><input class="easyui-textbox" type="text"  name="catId__2" id="catId" data-options="required:true"  style="width:250px;"></input></td>
                                        </tr>
                                        <tr>
                                            <td>商品品牌:</td>
                                            <td>
                                                <input name="brandId" id="brandId"  class="easyui-combobox"  style="width:250px;"
                                                       data-options="
                                                       required:true,
                                                       valueField:'id',
                                                       textField:'brandName',
                                                       editable:false,
                                                       method:'get',
                                                       panelHeight:'auto',
                                                       url:'${rc.contextPath}/admin/common/brand/list',
                                                       loadFilter:function(data){
                                                       	if(data.statusCode == normalStatusCode){
																			var arrayObj = [{id:'',name:'全部'}];
																			arrayObj = arrayObj.concat(data.entity);
																			return arrayObj;
																	}else {
																		return  [];
																	}
																  }">
                                            </td>
                                            <td>供应商:</td>
                                            <td>
                                                <input name="providerId" id="providerId"  class="easyui-combobox"  style="width:250px;"
                                                       data-options="
                                                       required:true,
                                                       valueField:'id',
                                                       textField:'name',
                                                       editable:false,
                                                       method:'get',
                                                       panelHeight:'auto',
                                                       url:'${rc.contextPath}/admin/common/suppliers/list',
                                                       loadFilter:function(data){
                                                       	if(data.statusCode == normalStatusCode){
																			var arrayObj = [{id:'0',name:'不指定供应商则为本店商品'}];
																			arrayObj = arrayObj.concat(data.entity);
																			return arrayObj;
																	}else {
																		return  [{id:'0',name:'不指定供应商则为本店商品'}];
																	}
																  }">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>本店售价:</td>
                                            <td><input class="easyui-numberbox" type="text" name="shopPrice" id="shopPrice" data-options="required:true,min:0,precision:2"  style="width:250px;"></input></td>

                                            <td>市场售价:</td>
                                            <td><input class="easyui-numberbox" type="text" name="marketPrice" id="marketPrice" data-options="required:true,min:0,precision:2"  style="width:250px;"></input></td>
                                        </tr>
                                        <tr>
                                            <td>赠送消费积分数:</td>
                                            <td><input class="easyui-numberbox" type="text" name="giveIntegral" id="giveIntegral" data-options="required:true,min:0,precision:0"  style="width:250px;"></input></td>

                                            <td>赠送等级积分数:</td>
                                            <td><input class="easyui-numberbox" type="text" name="rankIntegral" id="rankIntegral" data-options="required:true,min:0,precision:0"  style="width:250px;"></input></td>
                                        </tr>
                                        <tr>
                                            <td>积分购买金额:</td>
                                            <td><input class="easyui-numberbox" type="text" name="integral" id="integral" data-options="required:true,min:0,precision:0"  style="width:250px;"></input></td>

                                            <td>是否促销:</td>
                                            <td>
                                                <select id="isPromote" name="isPromote" class="easyui-combobox" data-options="editable:false,panelHeight:true,onChange:promoteChange"   style="width:250px;">
                                                    <option value="0">不促销</option>
                                                    <option value="1">促销</option>
                                                </select>

											</td>
                                        </tr>
                                        <tr>
                                            <td>促销价:</td>
                                            <td><input class="easyui-numberbox" type="text" name="promotePrice" id="promotePrice" data-options="required:true,min:0,precision:2"  style="width:250px;"></input></td>

                                            <td>促销日期:</td>
                                            <td>
                                                <input id="promoteStartDate" name="promoteStartDateString" type="text" class="easyui-datebox" required="required" data-options="editable:false">-
                                                <input id="promoteEndDate" name="promoteEndDateString" type="text" class="easyui-datebox" required="required"  data-options="editable:false">
											</td>
                                        </tr>
                                        <tr>
                                            <td>商品图片:</td>
                                            <td>
                                                <input class="easyui-filebox" name="goodsImgFile" data-options="buttonText:'选择图片',prompt:'选择图片...'" style="width:250px;">
                                                <br><input type="text" size="40" value="商品图片外部URL" style="color:#aaa;" onfocus="if (this.value == '商品图片外部URL'){this.value='http://';this.style.color='#000';}" name="goods_img_url">
                                            </td>
                                            <td>上传商品缩略图;</td>
                                            <td><input class="easyui-filebox" name="goods_thumb" data-options="buttonText:'选择图片',prompt:'选择图片...'" style="width:250px;">
                                                <br><input type="text" size="40" value="商品图片外部URL" style="color:#aaa;" onfocus="if (this.value == '商品图片外部URL'){this.value='http://';this.style.color='#000';}" name="goods_thumb_url"></td>
                                        </tr>
                                    </table>
								</div>

								<div title="其他信息" data-options="iconCls:'icon-help'" style="padding:5px">
                                    <table cellpadding="5">
                                        <tr>
                                            <td>商品重量:</td>
                                            <td><input class="easyui-numberbox" type="text" name="goodsWeight" id="goodsWeight" data-options="required:true,min:0,precision:0"  style="width:250px;"></input>
                                                <select id="weightUnit" name="weightUnit" class="easyui-combobox" data-options="editable:false,panelHeight:true"   style="width:70px;">
														<#list WeightUnitEnum.values() as val>
															<option value="${val.name()}">${val.getName()}</option>
														</#list>
                                                </select>

											</td>
                                            <td>&nbsp;</td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td>库存数量:</td>
                                            <td><input class="easyui-numberbox" type="text" name="goodsNumber__2" id="goodsNumber" data-options="required:true,min:0,precision:0"  style="width:250px;"></input></td>

                                            <td>库存警告数:</td>
                                            <td><input class="easyui-numberbox" type="text" name="warnNumber__2" id="warnNumber" data-options="required:true,min:0,precision:0"  style="width:250px;"></input></td>
                                        </tr>
                                        <tr>
                                            <td>加入推荐:</td>
                                            <td><input  type="checkbox" name="isBest" id="isBest" value="1"  ></input>精品 &nbsp;
                                                <input  type="checkbox" name="isNew" id="isNew" value="1"  ></input>新品&nbsp;
                                                <input  type="checkbox" name="isHot" id="isHot"  value="1" ></input>热销</td>

                                            <td>上架:</td>
                                            <td><input  type="checkbox" name="isOnSale" id="isOnSale" value="1"  ></input> &nbsp;
                                                打勾表示允许销售，否则不允许销售。
											</td>
                                        </tr>
                                        <tr>
                                            <td>作为普通商品销售:</td>
                                            <td><input  type="checkbox" name="isAloneSale" id="isAloneSale" value="1" checked="checked" ></input>&nbsp;
                                                打勾表示能作为普通商品销售，否则只能作为配件或赠品销售。
                                            </td>

                                            <td>是否免运费:</td>
                                            <td><input  type="checkbox" name="isShipping" id="isShipping" value="1"  ></input>&nbsp;
                                                打勾表示此商品不会产生运费花销，否则按照正常运费计算。
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>商品关键词:</td>
                                            <td colspan="3"><input class="easyui-textbox" type="text" name="keywords" id="keywords" data-options="multiline:true,height:60"  style="width:500px;"></input>用空格分隔</td>
                                        </tr>
                                        <tr>
                                            <td>商品简单描述</td>
                                            <td colspan="3"><input  type="text" id="goodsBrief" name="goodsBrief" class="easyui-textbox" data-options="multiline:true,height:60" style="width:500px"></input></td>

                                        </tr>
                                        <tr >
                                            <td>商家备注</td>
                                            <td colspan="3"><input  type="text" id="sellerNote" name="sellerNote" class="easyui-textbox" data-options="multiline:true,height:60" style="width:500px"></input>仅供商家自己看的信息</td>
                                        </tr>
                                    </table>
								</div>
                                <div title="详细描述" style="padding:5px">
                                    <textarea name="editor1" name="goodsDesc"></textarea>
                                </div>
								<div title="商品属性"    data-options="" style="padding:5px;width:100%">
                                    <div id="cc" class="easyui-layout"  data-options="fit:true" style="width:100%;height:100%;">
                                        <div data-options="region:'north',border:false" style="height:40px;" data-options="fit:true">
                                            <table cellpadding="5">
                                                <tr>
                                                    <td>商品类型:</td>
                                                    <td>
                                                        <input name="goodsType" id="goodsType"  class="easyui-combobox"  style="width:250px;"
                                                               data-options="
                                                       required:true,
                                                       valueField:'id',
                                                       textField:'name',
                                                       editable:false,
                                                       method:'get',
                                                       panelHeight:'auto',
                                                       url:'${rc.contextPath}/admin/common/goodstype/list',
                                                       onChange:goodsTypeChange,
                                                       loadFilter:function(data){
                                                       	if(data.statusCode == normalStatusCode){
																			var arrayObj = [{id:'',name:'待定'}];
																			arrayObj = arrayObj.concat(data.entity);
																			return arrayObj;
																	}else {
																		return  [];
																	}
																  }">
                                                        </input>
                                                    </td>
                                                </tr>
                                            </table>

										</div>
                                        <div data-options="region:'center'" data-options="fit:true" id="attributeTableDiv">

										</div>
                                    </div>

								</div>
								<div title="商品相册"   style="padding:5px">
                                    <div id="haveAddPicDiv"  title="已上传图片" style="height: 651px;">
                                        <table id="goodsGalleryTrable" class="easyui-datagrid" data-options="singleSelect:true,collapsible:false,fit:true">
                                            <thead>
                                                <tr>
                                                    <th data-options="field:'id',hidden:true">ID</th>
                                                    <th data-options="field:'imgUrl',width:100">图片</th>
                                                    <th data-options="field:'imgDesc',width:80">描述</th>
                                                    <th data-options="field:'opt',formatter:galleryOptFn">Unit Cost</th>
                                                </tr>
                                            </thead>
                                        </table>
                                    </div>
                                    <div id="addNetPicLayout"  title='新增图片' style="height: 651px;">
                                        <!-- 上传新照片 -->
                                        <table width="90%"   align="center" id="gallery-table">
                                            <tr>
                                                <td>
                                                    <a href="javascript:;" onclick="addImg(this)">[+]</a>
                                                    <input type="hidden" name="pic" value="1">
                                                    图片描述: <input type="text" name="img_descs" size="20" />
                                                    上传图片:<input type="file" name="img_urls" />
                                                    外部网址:<input type="text" name="img_files" size="30" value="http://" style="color:#aaa;" onfocus="if (this.value == 'http://'){this.value='http://';this.style.color='#000';}" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>


								</div>
								<#--<div title="关联商品" data-options="iconCls:'icon-help'" style="padding:5px">-->
                                    <#--<table width="90%" id="linkgoods-table" style="" align="center">-->
                                        <#--<!-- 鍟嗗搧鎼滅储 &ndash;&gt;-->
                                        <#--<tr>-->
                                            <#--<td colspan="3">-->

                                                <#--<select  name="catId_search" id="catId_search" class="easyui-combotree" style="width:250px;"-->
                                                         <#--data-options="url:'${rc.contextPath}/admin/common/category/list',-->
<#--buttonText:'分类',buttonAlign:'left',-->
                                                        <#--method:'get',-->
                                                         <#--panelHeight:'auto',-->
                                                         <#--valueField:'id',-->
                                                        <#--loadFilter:function(data){-->
                                                       	<#--if(data.statusCode == normalStatusCode){-->
																				<#--return treeloadFilter(data.entity,false);-->
																	<#--}else {-->
																		<#--return  [];-->
																	<#--}-->
                                                				<#--}-->
                                                       <#--">-->
                                                <#--</select>-->
                                                <#--<input name="brandId_search" id="brandId_search"  class="easyui-combobox"  style="width:250px;"-->
                                                       <#--data-options="-->
<#--buttonText:'品牌',buttonAlign:'left',-->
                                                       <#--valueField:'id',-->
                                                       <#--textField:'brandName',-->
                                                       <#--editable:false,-->
                                                       <#--method:'get',-->
                                                       <#--panelHeight:'auto',-->
                                                       <#--url:'${rc.contextPath}/admin/common/brand/list',-->
                                                       <#--loadFilter:function(data){-->
                                                       	<#--if(data.statusCode == normalStatusCode){-->
																			<#--var arrayObj = [{id:'',name:'全部'}];-->
																			<#--arrayObj = arrayObj.concat(data.entity);-->
																			<#--return arrayObj;-->
																	<#--}else {-->
																		<#--return  [];-->
																	<#--}-->
																  <#--}">-->
                                                <#--<input class="easyui-textbox" style="line-height:12px; width:200px"-->
                                                       <#--data-options="-->
<#--buttonText:'关键字',buttonAlign:'left'"-->
                                                       <#--id="keyword_search"/>-->
                                                <#--<a href="#"  class="easyui-linkbutton" iconCls="icon-search" onclick="searchGoods()">搜索</a>-->

                                            <#--</td>-->
                                        <#--</tr>-->
                                        <#--<!-- 工具条 &ndash;&gt;-->
                                        <#--<tr>-->
                                            <#--<th>可选商品</th>-->
                                            <#--<th>操作</th>-->
                                            <#--<th>跟该商品关联的商品</th>-->
                                        <#--</tr>-->
                                        <#--<tr>-->
                                            <#--<td width="42%">-->
                                                <#--<table id="link_goods_src_dg" class="easyui-datagrid"  data-options="-->
                                             <#--url:'${rc.contextPath}/admin/goods/dopage?d='+new Date().getTime(),-->
                                                <#--method: 'get',-->
                                                <#--fitColumns: true,-->
                                                <#--rownumbers: true,-->
                                                <#--pagination:true,-->
                                                <#--singleSelect:true,-->
                                                <#--fit:true,-->
                                                <#--pageSize:20,-->
                                                <#--columns:[[-->
                                                    <#--{field:'id',title:'id',hidden:true},-->
                                                    <#--{field:'goodsName',title:'名称' ,width:100}-->
                                                 <#--]],-->
                                              <#--loadFilter:function(data){-->
                                                   <#--if(data.statusCode == normalStatusCode){-->
                                                            <#--var obj = {};-->
                                                            <#--obj.total =  data.entity.totalRows;-->
                                                            <#--obj.rows = $.isArray(data.entity.pageData)?data.entity.pageData:[];-->
                                                            <#--return obj;-->
                                                   <#--}else {-->
                                                         <#--var obj = {};-->
                                                           <#--obj.total = 0;-->
                                                            <#--obj.rows = [];-->
                                                            <#--return obj;-->
                                                   <#--}-->
                                               <#--}-->
                                            <#--"></table>-->
                                            <#--</td>-->
                                            <#--<td align="center">-->
                                                <#--<p><input name="is_single" type="radio" value="1" checked="checked" />单向关联<br /><input name="is_single" type="radio" value="0" />双向关联</p>-->
                                                <#--<p><input type="button" value=">>" onclick="sz1_addItem(true, 'add_link_goods')" class="button" /></p>-->
                                                <#--<p><input type="button" value=">" onclick="sz1_addItem(false, 'add_link_goods' )" class="button" /></p>-->
                                                <#--<p><input type="button" value="<" onclick="sz1_addItem(false, 'drop_link_goods' )" class="button" /></p>-->
                                                <#--<p><input type="button" value="<<" onclick="sz1_addItem(true, 'drop_link_goods' )" class="button" /></p>-->
                                            <#--</td>-->
                                            <#--<td width="42%">-->
                                                <#--<table id="link_goods_value_dg" class="easyui-datagrid"  data-options="-->
                                            <#--fitColumns: true,-->
                                            <#--rownumbers: true,-->
                                            <#--singleSelect:true,-->
                                            <#--fit:true,-->
                                            <#--columns:[[-->
                                                <#--{field:'id',title:'id',hidden:true},-->
                                                <#--{field:'goodsName',title:'名称' ,width:100}-->
                                                <#--{field:'isDouble',title:'单双向' ,width:100}-->
                                             <#--]]-->
                                        <#--"></table>-->
                                            <#--</td>-->
                                        <#--</tr>-->
                                    <#--</table>-->
								<#--</div>-->
								<#--<div title="配件" data-options="iconCls:'icon-help'" style="padding:5px">-->
                                    <#--暂不开发-->
								<#--</div>-->
								<#--<div title="关联文章" data-options="iconCls:'icon-help'" style="padding:5px">-->
									<#--暂不开发-->
								<#--</div>-->
							</div>
                        </form>
					</div>

					<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
						<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:submitForm()">保存</a>
						<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:closeWinFn()">取消</a>
					</div>

			</div>
	</div>
     <div id="w_gallery" class="easyui-window" title="修改图集备注" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px;height:200px;padding:10px;">

         <div class="easyui-layout" data-options="fit:true">
             <div data-options="region:'center',border:false" style="padding:0px;">
                 <form id="ff"  method="post"   enctype="multipart/form-data"  style="height: 100%;" >
                         <table cellpadding="5">
                             <tr style="display: none">
                                 <td>id:</td>
                                 <td><input class="easyui-textbox" type="text" name="galleryId" id="galleryId" ></input></td>
                             </tr>
                             <tr>
                                 <td>备注:</td>
                                 <td><input class="easyui-textbox" name="goods_imgDesc" id="goods_imgDesc" data-options="multiline:true" style="height:60px"></input></td>
                             </tr>
                         </table>
                </form>
             </div>

             <div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
                 <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:submit2Form()">保存</a>
                 <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:close2WinFn()">取消</a>
             </div>


     </div>
<script type="text/javascript">
var doPage =  authIds.indexOf(",admin_goods_dopage,")>=0?true:false;
var doAddBtn =   authIds.indexOf(",admin_goods_doadd,")>=0?true:false;
var doupdateBtn =  authIds.indexOf(",admin_goods_doupdate,")>=0?true:false;
var dodelBtn =  authIds.indexOf(",admin_goods_dodel,")>=0?true:false;
var saveType="add"; 
$(function(){
    CKEDITOR.replace( 'editor1' );
 //   $.messager.alert('系统提示','未开发，暂用商品类型的页面!','info');
			if(!doAddBtn){
				$("#addBtn").hide();
			}
			$('#dg').datagrid({
			 	border:false,
				rownumbers:true,
				checkOnSelect:true,
				fitColumns:true,
				pagination:true,
				singleSelect:true,
				fit:true,
				pageSize:10,
				method:'get',
			  	url:'${rc.contextPath}/admin/goods/dopage?d='+new Date().getTime(),
			  	queryParams:{ },
			  	onBeforeLoad:function(param){
                    if(!doPage){
                        $.messager.alert('系统提示','您没有权限访问!','info');
                        return;
                    }
					param['pageno'] =  param['page']-1;
					param['pagesize']  = param['rows'];
			  		return true ;
			  	},
			  	onDblClickRow:function(rowIndex, rowData){
			  			//updateRowIndex = rowIndex;
						//getRoleInfoById(rowData['roleId']);
			  	},
			  	onLoadError:function(){
			  	},

				columns:[[
					{field:'id',title:'id',hidden:true},
					{field:'goodsName',title:'名称' ,width:100},
                    {field:'goodsSn',title:'货号' ,width:100},
                    {field:'catId',title:'分类ID' ,width:100},
                    {field:'brandId',title:'品牌ID' ,width:100},
                    {field:'providerName',title:'供应商' ,width:100},
                    {field:'goodsNumber',title:'库存' ,width:100},
                    {field:'marketPrice',title:'市场价' ,width:100},
                    {field:'shopPrice',title:'本店售价' ,width:100},
                    {field:'sortOrder',title:'推荐排序' ,width:100},
					{field:'states',title:'状态',width:100,formatter:function(value,row,index){
						if(value == 'ENABLE'){
							return "有效";
						}else  if(value == 'DISABLED'){
							return "不可用";
						}else  if(value == 'DEL'){
                            return "删除";
                        }
					}},
					{field:'opt',title:'操作' ,width:100,formatter:optFormat}
				]],
				toolbar: '#tb',
				loadFilter:function(data){
				   if(data.statusCode == normalStatusCode){
                        	var obj = {};
                            obj.total =  data.entity.totalRows;
                            obj.rows = $.isArray(data.entity.pageData)?data.entity.pageData:[];
                            return obj;
				   }else {
				            var obj = {};
                           obj.total = 0;
                            obj.rows = [];
                            return obj;
				   }

				}
			});

			var pager = $('#dg').datagrid("getPager");
			pager.pagination({
				'onBeforeRefresh':function(){
					searchFn();
					return false;
				}
			});
		});

		function searchFn(){
			if(!doPage){
				 $.messager.alert('系统提示','您没有权限访问!','info');
				return;
			}
			var brand_Name = $("#brand_Name").val();
			//var role_status = $('#role_status').combobox('getValue');
			$('#dg').datagrid('load',{
					//status:role_status,
                brandName:brand_Name,
					d:new Date().getTime()
			});

		}
		var resource_dg_loadSuccess = false;
		var updateRowIndex = -1;
var clickTime = 0;
		function addFn(){
			 saveType = "add";
           // $('#form1').form('reset');
			var page = getPageArea();
			var w = page.width;
            var h = page.height;
            var wh = h-20;
            $('#w').window('resize',{
                width: w,
                height:wh
            });

            showAddPicView(saveType,wh);
            var v = $('#isPromote').combobox("getValues");

            promoteChange(v);

 			 $('#w').window('open').panel('setTitle',"增加商品");
            $('#w').window('center');

		}
		function delFn(id){
			$.messager.confirm('系统提示', '您确定要删除该条记录吗?', function(r){
			if (r){
					var url = "${rc.contextPath}/admin/goods/dodel";
		  	 		$.ajax({
			  	  	  type:'post',
					  url: url,
					  context: document.body,
					  data:{
                          id: id,
					  	d:new Date().getTime()
					  },
					  success:function(data){

					  	if(data.statusCode == normalStatusCode){
							var row = null;
							var rows = $("#dg").datagrid("getRows");
							for(var i=0;i<rows.length;i++){
								if(rows[i]['id'] == id){
									row = rows[i];
									var rowIndex = 	$('#dg').datagrid("getRowIndex",row);
									$('#dg').datagrid("deleteRow",rowIndex);
									break;
								}
							}
					  		$.messager.alert('系统提示','删除成功!','info');

					  	}else{
					  		$.messager.alert('系统提示','删除失败，请刷新后重试!','error');
					  	}
					  },
					  error:function(xhr,textStatus,errorThrown){
					  	var responseText = xhr.responseText;
					  	$.messager.alert('系统提示','删除失败，请刷新后重试!','error');

					  }
				});

				}
			});
		}
		function optFormat (value,row,index){
			var btns = [];
			if(doupdateBtn){
				btns.push('<a class="easyui-linkbutton l-btn l-btn-plain" onclick="updateFn(\''+row['id']+'\')" href="#" plain="true" iconCls="update_btn"><span class="l-btn-left"><span class="l-btn-text update_btn l-btn-icon-left">修改</span></span></a>');
			}
			if(dodelBtn){
				btns.push('<a class="easyui-linkbutton l-btn l-btn-plain" onclick="delFn(\''+row['id']+'\')" href="#" plain="true" iconCls="del_btn"><span class="l-btn-left"><span class="l-btn-text del_btn l-btn-icon-left">删除</span></span></a>');
			}
			return btns.join("&nbsp;");
		}
		function updateFn(id){
			updateRowIndex = -1;
			var rows = $("#dg").datagrid("getRows");
			var row = null;
			for(var i=0;i<rows.length;i++){
				if(rows[i]['id'] == id){
					row = rows[i];
					break;
				}
			}

			var rowIndex =  $('#dg').datagrid("getRowIndex",row);
			 updateRowIndex = rowIndex;
            saveType = 'update'
         //   showAddPicView(saveType);
           // $('#form1').form('reset');
          //  $('#form1').form('load',row);
          //  $('#w').window('open').panel('setTitle',"修改商品类型");
            loadGoodsDataFromDbById(id);

		}
function loadGoodsDataFromDbById(goodsid){
    var url = "${rc.contextPath}/admin/goods/get";
    $.ajax({
        url: url,
        context: document.body,
        data:{
            id: goodsid,
            d:new Date().getTime()
        },
        success:function(data){　
            if(data.statusCode == normalStatusCode){
　               var goodsDto = data.entity
                var  dbGoodsGalleryList = goodsDto.dbGoodsGalleryList
//商品属性结构列表
               var  structureGoodsAttrList = goodsDto.structureGoodsAttrList
//商品属性值
               var  dbGoodsAttrList = goodsDto.dbGoodsAttrList;
//加载数据库数据
                $('#form1').form('reset');
                $('#form1').form('load',goodsDto);
                showAddPicView(saveType);
                $('#w').window('open').panel('setTitle',"修改商品类型");


            }else{
                $.messager.alert('系统提示','加载数据失败，请刷新后重试!','error');
            }
        },
        error:function(xhr,textStatus,errorThrown){
            var responseText = xhr.responseText;
            $.messager.alert('系统提示','加载数据失败，请刷新后重试!','error');

        }
    });
}

		function submitForm(){
            var url = "${rc.contextPath}/admin/goods/doadd";
            $('#form1').form('submit', {
                url:url,
                queryParams:{
                    ajax:true
                },
                onSubmit: function(param){
                    jQuery.showMask($("#w")[0],"正在保存中 ....");
                    var r = validateForm();
                    return r;

                },
                success: function(data){
                    jQuery.hideMask($("#w")[0]);
                    data = eval("("+data+")");
                    if(data.statusCode == normalStatusCode){
                        $('#dg').datagrid('reload');
                        if(saveType == 'add'){
                            $('#form1').form('reset');
                            $.messager.alert('系统提示','保存成功!','info');
                        }else if(saveType == 'update'){
                            $.messager.alert('系统提示','保存成功!','info',closeWinFn);
                        }

                    }else{
                        var errorEntity = data.entity;
                        if(errorEntity){
                            $.messager.alert('系统提示','保存失败,'+errorEntity.errorMsg,'warning');
                        }else{
                            $.messager.alert('系统提示','保存失败!','warning');
                        }
                    }

                }
            });
		}

		function closeWinFn(){
			$('#w').window('close');
		}
function treeloadFilter(menus ,usecheck){

    if(menus.length==0)return menus;
    var mapdata = {};
    //第一次组织树节点内容
    for(var i=0;i<menus.length;i++)
    {
        var node = menus[i];
        var menuname = node['catName'];

        var parentNo = node['parentId'];
        var aid = node['id'] ;

        mapdata["id_"+aid]= {
            id:aid,
            text:menuname,
            parentNo:parentNo,
            state:'closed',
            attributes:{
                parentId:parentNo
            }
        };

        if(usecheck)
        {
            mapdata["id_"+aid]['checked']=false;
        }

    }
    var ret = [];
    for(var key in mapdata)
    {
        var node = mapdata[key];
        var pid = mapdata[key]['parentNo'];
        if(mapdata["id_"+pid])
        {
            if(typeof mapdata["id_"+pid]['children'] == 'undefined')
            {
                mapdata["id_"+pid]['children'] = [];
            }
            mapdata["id_"+pid]['children'].push(mapdata[key]);
        }else
        {
            ret.push(mapdata[key]);
        }

    }
    for(var key in mapdata)
    {
        var node = mapdata[key];
        if(node['children'] == null){
            node['state'] = 'open';
        }

    }

    if(ret.length>0){ret[0]['state'] = 'open';}
    return ret;
}
var defalultGoodTypeId = "";
function goodsTypeChange(newValue, oldValue){
    if(oldValue == defalultGoodTypeId){

    }
    if(newValue == defalultGoodTypeId){
        //清空所有的
        $("#attributeTableDiv").html("");
    }else {
        var url = "${rc.contextPath}/admin/common/goods/goodsAttribute";
        $.ajax({
            url: url,
            context: document.body,
            data:{
                goodtypeid: newValue,
                d:new Date().getTime()
            },
            success:function(data){

                if(data.statusCode == normalStatusCode){

                    var tableHtml = attributeData2Html(data.entity);
                    $("#attributeTableDiv").html(tableHtml);
                }else{
                    $.messager.alert('系统提示','加载数据失败，请刷新后重试!','error');
                }
            },
            error:function(xhr,textStatus,errorThrown){
                var responseText = xhr.responseText;
                $.messager.alert('系统提示','加载数据失败，请刷新后重试!','error');

            }
        });
    }
}
    function attributeData2Html(attributeList){

            var outerTable = ["<table cellpadding='5'>"];

                var spec = '0';
            for(var i=0;i<attributeList.length;i++){

                var attribute = attributeList[i];
              //  alert(i +"==="+attribute['attrInputType']);
                outerTable.push('<tr>');
                    outerTable.push('<td>');
                        outerTable.push('<input type="hidden" name="attr_id_list" value="'+attribute['id']+'"/>');
                if (attribute['attrType'] == 'RADIO' || attribute['attrType'] == 'CHECKBOX')
                {
                    if((spec != attribute['id'])){
                        outerTable.push('<a href="javascript:;" onclick="addSpec(this)">[+]</a>');
                    }else {
                        outerTable.push('<a href="javascript:;" onclick="removeSpec(this)">[-]</a>');
                    }
                    spec = attribute['id'];
                }

                        outerTable.push(attribute['attrName']);
                    outerTable.push('</td>');
                    outerTable.push('<td>');
                if(attribute['attrInputType'] == "INPUT_PUT"){
                    outerTable.push('<input type="text" value="" name="attr_value_list"/>');
                }else if(attribute['attrInputType'] == "SELECT"){
                    try{
                    var vList_attrValues  = attribute['attrValues'];
                    var vList = vList_attrValues.split(";");
                    outerTable.push('<select  name="attr_value_list">');
                    for(var j =0;j < vList.length; j++){
                        var v = vList[j];
                        outerTable.push('<option value="'+v+'">'+v+'</option>');

                    }
                    outerTable.push('</select>');
                    }catch(error ){
                        alert(error);
                    }

                }else if(attribute['attrInputType'] == "MUL_TEXT"){
                    outerTable.push('<textarea   rows="3" cols="40" name="attr_value_list"></textarea>');
                }

                if(attribute['attrType'] == "RADIO" || attribute['attrType'] == "CHECKBOX"){
                    outerTable.push('属性价格：<input type="text" value=""  name="attr_price_list"  size="5" maxlength="10"/>');
                }else{
                    outerTable.push('<input type="hidden" name="attr_price_list" value="0" />');
                }
                outerTable.push('</td>');
                outerTable.push('</tr>');
            }
            outerTable.push('</table>');
            var h = outerTable.join("");

        return h;
    }

var adding = false;
function addImg(obj)
{
    if(!adding){
        adding = true;
        var d = new Date().getTime();

        $(obj).html("[-]");
        $(obj).attr("onclick","removeImg(this)");

        var newTr = [];
        newTr.push('<tr>');
        newTr.push('<td>');
        newTr.push('<a href="javascript:;" onclick="addImg(this)">[+]</a>');
        newTr.push(' <input type="hidden" name="pic" value="'+d+'">');
        newTr.push('图片描述: <input type="text" name="img_descs" size="20" />');
        newTr.push('上传图片:<input type="file" name="img_urls" />');
        newTr.push(' 外部网址:<input type="text" name="img_files" size="40" value="http://" style="color:#aaa;" onfocus="if (this.value == \'http://\'){this.value=\'http://\';this.style.color=\'#000\';}" />');
        newTr.push(' </td>');
        newTr.push('</tr>');

        $("#gallery-table ").append(newTr.join(""));
        adding = false;
    }

}
function removeImg(obj)
{
    var row = obj.parentNode.parentNode.rowIndex;
    var tbl = document.getElementById('gallery-table');
    tbl.deleteRow(row);
}
    function showAddPicView(saveType,wh){

        if(saveType == 'add'){

           $("#addNetPicLayout").height( wh);
            $("#haveAddPicDiv").hide();
            $("#addNetPicLayout").show();

        }else if(saveType == 'update'){

             $("#addNetPicLayout").height( wh/2);
            $("#haveAddPicDiv").show();
             $("#haveAddPicDiv").height( wh/2);
        }
    }
    function dlList(){
        $('#dl').datalist({
            url: '${rc.contextPath}/admin',
            checkbox: true,
            lines: true
        });
    }

    function searchGoods( cat_id1,brand_id1,keyword1){
          var  cat_id = $('#catId_search').combobox("getValue");
          var  brand_id = $('#brandId_search').combobox("getValue");
          var  keywords = $('#keyword_search').textbox('getValue');

        $('#link_goods_src_dg').datagrid('load',{
            //status:role_status,
            brandId:brand_id,
            catId:cat_id,
            keywords:keywords,
            d:new Date().getTime()
        });


    }
    function sz1_addItem(){

    }
function validateForm(){
    //
    var errorMsg = [];
    var goodsName = $.trim( $('#goodsName').textbox("getValue"));
    if(goodsName.length ==0){
        errorMsg.push("商品名称不能为空");
    }

   var goodsSn = $.trim( $('#goodsSn').textbox("getValue"));
    if(goodsSn.length ==0){
        errorMsg.push("商品货号不能为空");
    }

    var catId = $.trim( $('#catId').combotree("getValue"));
    if(catId.length ==0){
        errorMsg.push("商品分类必须选择");
    }

    var shopPrice  =$.trim( $('#shopPrice').numberbox("getValue"));
    if(!$.isNumeric(shopPrice)  ){
        errorMsg.push("本店售价不是数字");
    }
    var marketPrice =  $.trim( $('#marketPrice').numberbox("getValue"));
    if(!$.isNumeric(marketPrice)  ){
        errorMsg.push("市场价不是数字");
    }
    var isPromote = $('#isPromote').combobox("getValue");
    if("1" == isPromote){
        var promoteStartDate = $.trim($('#promoteStartDate').datetimebox('getValue'));
        var promoteEndDate = $.trim($('#promoteEndDate').datetimebox('getValue'));
        if(promoteStartDate.length == 0){
            errorMsg.push("促销开始日期不能为空");
        }
        if(promoteEndDate.length == 0){
            errorMsg.push("促销结束日期不能为空");
        }
        if ( promoteStartDate.length != 0 || promoteEndDate.length != 0) {
            var d_start = promoteStartDate.split("-");
            var d_end = promoteEndDate.split("-");
            var start = Date.UTC(d_start[0],d_start[1],d_start[2],0,0,0,0)
            var end =   Date.UTC(d_end[0],d_end[1],d_end[2],0,0,0,0)

            if(end < start){
                errorMsg.push("促销结束日期不能小于促销开始结束日期");
            }
        }

       // alert("promoteStartDate="+promoteStartDate);
       // alert("promoteEndDate="+promoteEndDate);
    }
    var giveIntegral =   $.trim( $('#giveIntegral').numberbox("getValue"));
    var rankIntegral =  $.trim( $('#rankIntegral').numberbox("getValue"));
    var integral =  $.trim( $('#rankIntegral').numberbox("getValue"));
    if(giveIntegral.length == 0){
        $('#giveIntegral').numberbox("setValue",-1);
    }
    if(rankIntegral.length == 0){
        $('#rankIntegral').numberbox("setValue",-1);
    }
    if(integral.length == 0){
        $('#integral').numberbox("setValue",0);
    }
     var goodsNumber =  $.trim( $('#goodsNumber').numberbox("getValue"));
     var warnNumber =   $.trim( $('#warnNumber').numberbox("getValue"));
    if(!$.isNumeric(goodsNumber)  ){
        errorMsg.push("库存请输入数字");
    }
    if(!$.isNumeric(warnNumber)  ){
        errorMsg.push("库存警告数请输入数字");
    }
    if(errorMsg.length > 0){
        $.messager.alert('系统提示',errorMsg.join("<br/>"),'error');
        return false;
    }

    return true;
}
function promoteChange(newValue, oldValue){
        if(newValue == "1"){

            $('#promotePrice').numberbox('enable');
            $('#promoteStartDate').datetimebox('enable');
            $('#promoteEndDate').datetimebox('enable');
        }else {
            $('#promotePrice').numberbox('disable');
            $('#promoteStartDate').datetimebox('disable');
            $('#promoteEndDate').datetimebox('disable');
        }
}
function addSpec(obj)
{

    var trEl = $(obj).parent().parent();
    var cloneTrEl = trEl.clone();//.insertAfter(trEl);


    var tdEls = trEl.find('td');
    var td1 = $(tdEls[0]);
    td1.html (td1.html().replace(/(.*)(addSpec)(.*)(\[)(\+)/i, "$1removeSpec$3$4-"));


    var attr_value_lists = cloneTrEl.find("[name='attr_value_list']");
    attr_value_lists.val("");

    var attr_price_lists = cloneTrEl.find("[name='attr_price_list']");
    attr_price_lists.val("");

    cloneTrEl.insertAfter(trEl);// insertAfter,insertBefore
}

/**
 *
 */
function removeSpec(obj)
{
    var trEl = $(obj).parent().parent();
    trEl.remove();
}
    function galleryOptFn (value,row,index){
        var btns = [];
        btns.push('<a class="easyui-linkbutton l-btn l-btn-plain" onclick="updateGalleryFn(\''+row['id']+'\')" href="#" plain="true" iconCls="update_btn"><span class="l-btn-left"><span class="l-btn-text update_btn l-btn-icon-left">修改</span></span></a>');
        btns.push('<a class="easyui-linkbutton l-btn l-btn-plain" onclick="delGalleryFn(\''+row['id']+'\')" href="#" plain="true" iconCls="del_btn"><span class="l-btn-left"><span class="l-btn-text del_btn l-btn-icon-left">删除</span></span></a>');
        return btns.join("&nbsp;");
    }
    function updateGalleryFn(id){
        //修改图集备注
        var rows = $("#goodsGalleryTrable").datagrid("getRows");
        var row = null;
        for(var i=0;i<rows.length;i++){
            if(rows[i]['id'] == id){
                row = rows[i];
                break;
            }
        }

        $("#galleryId").val(id);
        $("#goods_imgDesc").val(row['imgDesc']);

        $('#w_gallery').window('open');
    }
    function delGalleryFn(id){
        //删除图集
        $.messager.confirm('系统提示', '您确定要删除该条记录吗?', function(r){
            if (r){
                var url = "${rc.contextPath}/admin/goods/grllery/dodel";
                $.ajax({
                    type:'post',
                    url: url,
                    context: document.body,
                    data:{
                        id: id,
                        d:new Date().getTime()
                    },
                    success:function(data){

                        if(data.statusCode == normalStatusCode){
                            var row = null;
                            var rows = $("#goodsGalleryTrable").datagrid("getRows");
                            for(var i=0;i<rows.length;i++){
                                if(rows[i]['id'] == id){
                                    row = rows[i];
                                    var rowIndex = 	$('#dg').datagrid("getRowIndex",row);
                                    $('#dg').datagrid("deleteRow",rowIndex);
                                    break;
                                }
                            }
                            $.messager.alert('系统提示','删除成功!','info');

                        }else{
                            $.messager.alert('系统提示','删除失败，请刷新后重试!','error');
                        }
                    },
                    error:function(xhr,textStatus,errorThrown){
                        var responseText = xhr.responseText;
                        $.messager.alert('系统提示','删除失败，请刷新后重试!','error');

                    }
                });

            }
        });
    }
    function submit2Form(){

        var url = "${rc.contextPath}/admin/goods/grllery/doupdate";
        $('#ff').form('submit', {
            url:url,
            queryParams:{
                ajax:true
            },
            onSubmit: function(param){
                jQuery.showMask($("#w")[0],"正在保存中 ....");
                var r = validateForm();
                return r;

            },
            success: function(data){
                jQuery.hideMask($("#w")[0]);
                data = eval("("+data+")");
                if(data.statusCode == normalStatusCode){
                    $('#dg').datagrid('reload');
                    if(saveType == 'add'){
                        $('#ff').form('reset');
                        $.messager.alert('系统提示','保存成功!','info');
                    }else if(saveType == 'update'){
                        $.messager.alert('系统提示','保存成功!','info',closeWinFn);
                    }

                }else{
                    var errorEntity = data.entity;
                    if(errorEntity){
                        $.messager.alert('系统提示','保存失败,'+errorEntity.errorMsg,'warning');
                    }else{
                        $.messager.alert('系统提示','保存失败!','warning');
                    }
                }

            }
        });
    }
    function close2WinFn(){
        $('#w_gallery').window('close');
    }

	</script>
</body>
</html>